class MinigameKillerObject extends MinigamePhysicsObject;

// Deal with recycling

var() bool    Recycle;
var() range   RecycleLifeSpan;
var() range   RecycleSpawnTime;

var float     ElapsedTime;
var float     StartTime;
var float     DestinationTime;
var bool      TimesSet;

var vector    SpawnLocation;
var rotator   SpawnRotation;
var() rangevector  SpawnImpact;
var() rangevector  SpawnVelocity;

var() bool    RunOnlyInSameVolume;

simulated event PreBeginPlay () {

     SpawnLocation = Location;
     SpawnRotation = Rotation;

}

simulated event Tick (float DeltaTime) {

    local vector tempVelocity;
    local vector tempImpact;
    local EnyaraPlayerController PC;

    PC = EnyaraPlayerController(level.GetLocalPlayerController());

    if (RunOnlyInSameVolume && PC.Pawn.PhysicsVolume != self.PhysicsVolume) {
        super.Tick(DeltaTime);
        return;
    }

    if (Recycle) {

        ElapsedTime += DeltaTime;

        if (KIsAwake()) {

            if (ElapsedTime > DestinationTime) {
                SetPhysics(PHYS_None);
                SetLocation(SpawnLocation);
                SetRotation(SpawnRotation);
                SetPhysics(PHYS_Karma);
                TimesSet = false;
            }

        } else {

            if (!TimesSet) {

                TimesSet = true;
                ElapsedTime = 0;
                StartTime = FRand()*(RecycleSpawnTime.Max-RecycleSpawnTime.Min)+RecycleSpawnTime.Min;
                DestinationTime = StartTime + FRand()*(RecycleLifeSpan.Max-RecycleLifeSpan.Min)+RecycleLifeSpan.Min;

            } else {

                if (ElapsedTime > StartTime) {
                    KWake();
                    tempVelocity.X = Frand()*(SpawnVelocity.X.Max-SpawnVelocity.X.Min)+SpawnVelocity.X.Min;
                    tempVelocity.Y = Frand()*(SpawnVelocity.Y.Max-SpawnVelocity.Y.Min)+SpawnVelocity.Y.Min;
                    tempVelocity.Z = Frand()*(SpawnVelocity.Z.Max-SpawnVelocity.Z.Min)+SpawnVelocity.Z.Min;
                    tempImpact.X = Frand()*(SpawnImpact.X.Max-SpawnImpact.X.Min)+SpawnImpact.X.Min;
                    tempImpact.Y = Frand()*(SpawnImpact.Y.Max-SpawnImpact.Y.Min)+SpawnImpact.Y.Min;
                    tempImpact.Z = Frand()*(SpawnImpact.Z.Max-SpawnImpact.Z.Min)+SpawnImpact.Z.Min;
                    KAddImpulse(tempVelocity, tempImpact);
                }

            }

        }

    }

    super.Tick(DeltaTime);
}

simulated event Touch( Actor Other ) {

    local EnyaraPlayerController PC;
    PC = EnyaraPlayerController(Level.GetLocalPlayerController());

    if (PC.DeathCountdown == false && Other == PC.Pawn) {
        PC.PlayerKill();
    }

}

defaultproperties {

    bBlockActors=false

    Recycle=true
    RecycleLifeSpan=(Min=5,Max=7)
    RecycleSpawnTime=(Min=0,Max=2)
    SpawnVelocity=(X=(Min=0,Max=0),Y=(Min=0,Max=0),Z=(Min=0,Max=0))
    SpawnImpact=(X=(Min=0,Max=0),Y=(Min=0,Max=0),Z=(Min=0,Max=0))
    ElapsedTime=0
    DestinationTime=0
    StartTime=0
    TimesSet=false
    RunOnlyInSameVolume=true

}
